package com.jia.leetCode;

/**
 * 941.有效的山脉数组
 *
 *
 */
public class Pro0941 {
    public boolean validMountainArray(int[] A) {
        boolean isInc = false;
        boolean isDesc = false;
        int preA = -1;
        for(int i = 0; i < A.length; i++) {
            if(i != 0) {
                if(!isInc) {
                    //找递增
                    if(preA >= A[i]) {
                        return false;
                    }else if(preA < A[i]) {
                        isInc = true;
                        while(i < A.length - 1 && A[i] < A[i+1]) { preA = A[i+1]; i++; }//跑完剩下递增的
                    }
                }else {
                    //找递减
                    if(preA <= A[i]) {
                        return false;
                    }else if(preA > A[i]) {
                        isDesc = true;
                    }
                }
            }
            preA = A[i];
        }
        return isInc && isDesc;
    }
}
